package messages;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;

public class ByteListTest {

	@Test
    public void testEmpty()
    {
        ByteList list = new ByteList();
        
        assertEquals(0, list.getSize());
        assertEquals(0, list.toByteArray().length);
    }
    
	@Test
    public void testCopyList()
    {
        ArrayList<Byte> arrList = new ArrayList<Byte>();
        arrList.add((byte) 8);
        arrList.add((byte) 12);
        arrList.add((byte) 92);
        arrList.add((byte) -67);
        
        ByteList list = new ByteList(arrList);
        
        assertEquals(arrList.size(), list.getSize());
        byte[] arr = list.toByteArray();
        assertEquals(arrList.size(), arr.length);
        for (int i = 0;i < arrList.size();i++)
        {
            assertTrue(arrList.get(i).equals(arr[i]));
        }
    }
    
	@Test
    public void testCopyArray()
    {
        byte[] arrList = new byte[] { 8, 12, 92, -67 };
        
        ByteList list = new ByteList(arrList);
        
        assertEquals(arrList.length, list.getSize());
        byte[] arr = list.toByteArray();
        assertEquals(arrList.length, arr.length);
        for (int i = 0;i < arrList.length;i++)
        {
            assertTrue(arrList[i] == arr[i]);
        }
    }
    
	@Test
    public void testAdd()
    {
        ByteList list = new ByteList();
        
        assertTrue(list.addByte((byte) 2));
        assertEquals(1, list.getSize());
        
        byte[] arr = list.toByteArray();
        assertEquals(1, arr.length);
        assertEquals(2, arr[0]);
    }
    
	@Test
    public void testMultipleAdd()
    {
        ByteList list = new ByteList();
        
        assertTrue(list.addByte((byte) 2));
        assertTrue(list.addByte((byte) 8));
        assertTrue(list.addByte((byte) -3));
        
        assertEquals(3, list.getSize());
        
        byte[] arr = list.toByteArray();
        assertEquals(3, arr.length);
        assertEquals(2, arr[0]);
        assertEquals(8, arr[1]);
        assertEquals(-3, arr[2]);
    }

}
